import * as React from 'react'
import { Route, Switch, Redirect, RouteProps } from 'react-router-dom';
import NotFound from '../components/notFound'
import Loading from '../components/loading'
const { lazy, Suspense } = React
const Home = lazy(() => import( /* webpackChunkName:"inside" */ '../pages/inside/neibin'))
// const Neibin = lazy(() => import( /* webpackChunkName:"neibin" */ '../pages/inside/neibin'))
const Sanke = lazy(() => import( /* webpackChunkName:"neibin" */ '../pages/inside/sanke/index'))//散客列表
const Add = lazy(() => import( /* webpackChunkName:"Add" */ '../pages/inside/neibin/add')) // 新增入住
const Visitor = lazy(() => import( /* webpackChunkName:"Visitor" */ '../pages/inside/visitor/index')) //访客中心
const Info = lazy(() => import( /* webpackChunkName:"Info" */ '../pages/system/info/info')) //酒店信息
const Room = lazy(() => import( /* webpackChunkName:"Room" */ '../pages/system/room/list')) //房间信息
export const routes: RouteProps[] = [
  {
    path: '/sanke',
    exact: true,
    component: Sanke
  },    
  {
    path: '/inside/Add',
    exact: true,
    component: Add
  },    
  {
    path: '/',
    exact: true,
    component: Home
  },  
  {
    path: '/Info',
    exact: true,
    component: Info
  },
  {
    path: '/Room',
    exact: true,
    component: Room
  },  
  {
    path: '/Visitor',
    exact: true,
    component: Visitor
  },    
  {
    path: '*',
    component: NotFound
  },
]

const Routes = (authorized: boolean) => <Suspense fallback={<Loading></Loading>}>
  <Switch>
    {
      routes.map(r => {
        const { path, exact, component } = r
        const LazyCom: keyof JSX.IntrinsicElements | any = component
        return <Route key={path + ''} exact={!!exact} path={path} render={(props: any) => (authorized ? <LazyCom {...props} /> : <Redirect to="/login" />)} />
      })
    }
  </Switch>
</Suspense>

export default Routes